<template>
  <div class="q-pb-lg" :id="'rating-' + field.name">
    <div class="text-grey-7">{{field.label}}</div>
    <div>
      <q-rating
        v-model="field.value"
        size="md"
        :color="field.color || 'yellow'"
        :icon="field.icon || 'star_border'"
        :icon-selected="field.iconSelected || 'star'"
      />
    </div>
    <div class="text-bold text-white bg-yellow-10" style="padding: 1px;" v-if="canShowCompare">
      {{field.compare.label ? field.compare.label + '：' : ''}}{{field.compare.map ? field.compare.map.value : field.compare.value}}
    </div>
    <div class="hint" v-if="field.hint">{{field.hint}}</div>
  </div>
</template>
<script>
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'fieldRating',
  props: {
    field: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {

    }
  },
  computed: {
    canShowCompare () {
      /*
        compare的值
        compare: {
          label, // 标题
          value, // 对比的值
          always // true-有数据就显示 false-值不同，再显示
        } */
      return this.field.compare && this.field.compare.value !== null && (this.field.compare.always || this.field.compare.value != this.field.value);
    }
  }
});
</script>

<style scoped>
.hint {
  font-size: 12px;
  min-height: 20px;
  line-height: 1;
  color: rgba(0, 0, 0, 0.54);
  padding: 8px 12px 0;
}
.compare {
  font-size: 12px;
  min-height: 20px;
  line-height: 1;
  padding: 8px 12px 0;
}
</style>
